using MicroMsg.Common.Utils;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.UserContrl
{
	public class SnsMessageItem : UserControl
	{
		private CommentMsgCtrl commnetCtrl;
		private SnsLoadingCtrl snsLodingCtrl;
		public static DependencyProperty ListItemProperty = DependencyProperty.Register("ItemObject", typeof(SnsMsg), typeof(SnsMessageItem), new PropertyMetadata(null, new PropertyChangedCallback(SnsMessageItem.OnItemPropertyChanged)));
		internal Grid LayoutRoot;
		private bool _contentLoaded;
		public SnsMsg ItemObject
		{
			get
			{
				return (SnsMsg)base.GetValue(SnsMessageItem.ListItemProperty);
			}
			set
			{
				base.SetValue(SnsMessageItem.ListItemProperty, value);
			}
		}
		public SnsMessageItem()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.SnsMessageItem_Loaded));
		}
		private void SnsMessageItem_Loaded(object sender, RoutedEventArgs e)
		{
		}
		private static void OnItemPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == SnsMessageItem.ListItemProperty)
			{
				(dependencyObject_0 as SnsMessageItem).OnListItemPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void OnListItemPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			try
			{
				this.RefreshItem(dependencyPropertyChangedEventArgs_0.get_NewValue() as SnsMsg);
			}
			catch (Exception ex)
			{
				Log.smethod_1(base.GetType().get_Name(), ex.get_StackTrace());
			}
		}
		private void RefreshItem(SnsMsg item)
		{
			if (item == null)
			{
				return;
			}
			this.commnetCtrl = (CommentMsgCtrl)UIElementTraveler.FindElementRecursive(this, typeof(CommentMsgCtrl));
			this.snsLodingCtrl = (SnsLoadingCtrl)UIElementTraveler.FindElementRecursive(this, typeof(SnsLoadingCtrl));
			if (!(item.strObjectID == "LoadingMode") && !(item.strObjectID == "ToLoadMode") && !(item.strObjectID == "ClickMode"))
			{
				if (this.commnetCtrl == null)
				{
					this.LayoutRoot.get_Children().Clear();
					this.commnetCtrl = new CommentMsgCtrl();
					this.snsLodingCtrl = null;
					this.LayoutRoot.get_Children().Add(this.commnetCtrl);
				}
				this.commnetCtrl.Refresh(item);
				return;
			}
			if (this.snsLodingCtrl != null)
			{
				return;
			}
			this.LayoutRoot.get_Children().Clear();
			this.snsLodingCtrl = new SnsLoadingCtrl();
			if (item.strObjectID == "LoadingMode")
			{
				this.snsLodingCtrl.modeType = LoadingState.LoadingMode;
			}
			else
			{
				if (item.strObjectID == "ToLoadMode")
				{
					this.snsLodingCtrl.modeType = LoadingState.PullToShowMoreMode;
				}
				else
				{
					if (item.strObjectID == "ClickMode")
					{
						this.snsLodingCtrl.modeType = LoadingState.ClickToShowMoreMode;
					}
				}
			}
			this.snsLodingCtrl.ItemClick += new SnsLoadingCtrl.LoadingCtrlClick(this.snsLodingCtrl_ItemClick);
			this.commnetCtrl = null;
			this.LayoutRoot.get_Children().Add(this.snsLodingCtrl);
		}
		private void snsLodingCtrl_ItemClick(object sender, object object_0)
		{
			LoadingState loadingState = (LoadingState)object_0;
			if (loadingState != LoadingState.ClickToShowMoreMode)
			{
				return;
			}
			BasePage rootPage = ToolFunction.GetRootPage();
			if (rootPage is SnsMessageListPage)
			{
				SnsMessageListPage snsMessageListPage = rootPage as SnsMessageListPage;
				if (snsMessageListPage.initMsgNum != 0)
				{
					if (snsMessageListPage.itemSource != null && snsMessageListPage.itemSource.get_Count() != 0)
					{
						SnsMsg snsMsg = new SnsMsg();
						snsMsg.strObjectID = "ToLoadMode";
						snsMessageListPage.itemSource.set_Item(snsMessageListPage.itemSource.get_Count() - 1, snsMsg);
					}
					snsMessageListPage.LoadMore();
					snsMessageListPage.initMsgNum = 0;
				}
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Sns/Common/UI/SnsMsg/SnsMessageItem.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
		}
	}
}
